package edu.mit.media.fv.aqview
{
	import edu.mit.media.fv.blocks.*;
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	import edu.mit.media.fv.aqwidgets.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	public class AQVoiceViewer extends AQViewer
	{
		var _tags:AQTextField;
		var _sender:AQTextField;
		var _date:AQTextField;
		var _player:AQPlayer;
		var _sendButton:DisplayObject;
		var _goodButton:DisplayObject;
		var _badButton:DisplayObject;
		
		private var audioID:int;
		private var isInitialized:Boolean = false;
		
		public function AQVoiceViewer()
		{
			super();
			FluidEventHandler.addEventListener(DisplayEvent.OPEN_VOICE, displayWidget);
		
		}
		public function displayWidget(event:DisplayEvent = null):void{
			if(!isInitialized){
				this._player.addEventListener(AQRecorderEvent.START_PLAY, pressStartPlay);
				this._player.addEventListener(AQRecorderEvent.STOP_PLAY, pressStopPlay);
				isInitialized = true;
			}
			FluidEventHandler.dispatchEvent(new WidgetEvent(WidgetEvent.DISPLAY_WIDGET, this, "VMail"));
			this._tags.text = event.subject;
			this._date.text = event.date;
			this._sender.text = event.sourceName;
			this.id = event.id;
			this.audioID = event.audioID;
			
			
		}
		private function replyMessage(event:MouseEvent):void{
			var e:WidgetEvent = new WidgetEvent(WidgetEvent.DISPLAY_VOICE_BUILDER);
			e.subject = this._tags.text;
			e.id = this.id;
			FluidEventHandler.dispatchEvent(e);
		}

		public function pressStartPlay(event:AQRecorderEvent):void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_START_PLAY;
			data.id = this.audioID;
			var e:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(e);
		}
		public function pressStopPlay(event:AQRecorderEvent):void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_STOP_PLAY;
			data.id = this.audioID;
			var e:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(e);
		}
	}
}